package com.l.im.common.thread;


import java.util.concurrent.*;

/**
 * @program: LIM
 * @description: 线程池
 * @author: Alex Wu
 * @createDate: 2025-04-16 16:07
 **/
public class AsyncExecutor {
    private static final ExecutorService executorService = new ThreadPoolExecutor(
            4, // core
            10, // max
            60L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(100),
            new ThreadFactory() {
                private final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
                @Override
                public Thread newThread(Runnable r) {
                    Thread t = defaultFactory.newThread(r);
                    t.setName("async-executor-" + t.getId());
                    return t;
                }
            },
            new ThreadPoolExecutor.AbortPolicy() // 可根据需要换策略
    );

    public static void execute(Runnable task) {
        executorService.execute(task);
    }

    public static void shutdown() {
        executorService.shutdown();
    }
}
